/*
 * TextFieldColor.java
 *
 * 
 */
package it.luigiarpino.alt2jsim.utility;

import javax.swing.JTextField;
import java.awt.Color;


/**
 *
 * @author  Luigi Lorenzo Arpino 534/559
 */
public class TextFieldColor extends JTextField {
    
    /**
	 * 
	 */
	private static final long serialVersionUID = -5951096553849541923L;
	private Color coloreSfondo;
    
    /** Creates a new instance of JTextBoxColor */
    public TextFieldColor() {
        super();
        this.coloreSfondo=Color.YELLOW;
        this.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                FuocoRicevuto(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                FuocoPerso(evt);
            }
        });
    }
    
    
    public TextFieldColor(int i){
        super(i);
        this.coloreSfondo=Color.YELLOW;
        this.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                FuocoRicevuto(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                FuocoPerso(evt);
            }
        });
    }
    
    
    /** Creates a new instance of JTextBoxColor 
     permette di impostare il colore di sfondo*/
    public TextFieldColor(Color coloreSfondo_) {
        super();
        this.coloreSfondo=coloreSfondo_;
        this.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                FuocoRicevuto(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                FuocoPerso(evt);
            }
        });
    }
    
    
    private void FuocoPerso(java.awt.event.FocusEvent evt) {
        this.setBackground(Color.WHITE);
    }

    
    private void FuocoRicevuto(java.awt.event.FocusEvent evt) {
        this.setBackground(this.coloreSfondo);
        this.setSelectionStart(0);
        this.setSelectionEnd(this.getText().length());
    }
        

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
    }
    
    
}
